home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / RRectShp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.0 KB  |  293 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                RRectShp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef BASESHP_H
  15. #include "BaseShp.h"
  16. #endif
  17.  
  18. #ifndef BOUNDSHP_H
  19. #include "BoundShp.h"
  20. #endif
  21.  
  22. #ifndef RRECTSHP_H
  23. #include "RRectShp.h"
  24. #endif
  25.  
  26. #ifndef UTILS_H
  27. #include "Utils.h"
  28. #endif
  29.  
  30. #ifndef CONSTANT_H
  31. #include "Constant.h"
  32. #endif
  33.  
  34. #ifndef DRAWPART_H
  35. #include "DrawPart.h"
  36. #endif
  37.  
  38. #ifndef DRAWPART_H
  39. #include "DrawPart.h"
  40. #endif
  41.  
  42. #ifndef DRAWFRM_H
  43. #include "DrawFrm.h"
  44. #endif
  45.  
  46. #ifndef DRAWPRXY_H
  47. #include "DrawPrxy.h"
  48. #endif
  49.  
  50. #ifndef DRAWLINK_H
  51. #include "DrawLink.h"
  52. #endif
  53.  
  54. #ifndef DRAWCLIP_H
  55. #include "DrawClip.h"
  56. #endif
  57.  
  58. // ----- Part Layer -----
  59.  
  60. #ifndef FWFRMING_H
  61. #include "FWFrming.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWSELECT_H
  69. #include "FWSelect.h"
  70. #endif
  71.  
  72. #ifndef FWITERS_H
  73. #include "FWIters.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWEVENT_H
  79. #include "FWEvent.h"
  80. #endif
  81.  
  82. #ifndef FWRECSHP_H
  83. #include "FWRecShp.h"
  84. #endif
  85.  
  86. #ifndef FWTXTBOX_H
  87. #include "FWTxtBox.h"
  88. #endif
  89.  
  90. #ifndef FWLINSHP_H
  91. #include "FWLinShp.h"
  92. #endif
  93.  
  94. #ifndef FWOVLSHP_H
  95. #include "FWOvlShp.h"
  96. #endif
  97.  
  98. #ifndef FWRRCSHP_H
  99. #include "FWRRcShp.h"
  100. #endif
  101.  
  102. #ifndef FWODGEOM_H
  103. #include "FWODGeom.h"
  104. #endif
  105.  
  106. #ifndef FWGRUTIL_H
  107. #include "FWGrUtil.h"
  108. #endif
  109.  
  110. // ----- Foundation Includes -----
  111.  
  112. #ifndef FWSTREAM_H
  113. #include "FWStream.h"
  114. #endif
  115.  
  116. // ----- OpenDoc Includes -----
  117.  
  118. #ifndef SOM_ODTransform_xh
  119. #include <Trnsform.xh>
  120. #endif
  121.  
  122. //========================================================================================
  123. // Runtime Information
  124. //========================================================================================
  125.  
  126. #ifdef FW_BUILD_MAC
  127. #pragma segment odfdrawshapes
  128. #endif
  129.  
  130. //========================================================================================
  131. // RunTime Info
  132. //========================================================================================
  133.  
  134. FW_DEFINE_AUTO(CRoundRectShape)
  135. FW_DEFINE_CLASS_M1(CRoundRectShape, CBoundedShape)
  136.  
  137. const FW_ClassTypeConstant LRoundRectShape = FW_TYPE_CONSTANT('s','h','r','r');
  138. FW_REGISTER_ARCHIVABLE_CLASS(LRoundRectShape, CRoundRectShape, CRoundRectShape::Read, 0, 0, CBaseShape::Write)
  139.  
  140. //========================================================================================
  141. // class CRoundRectShape
  142. //========================================================================================
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // CRoundRectShape::CRoundRectShape
  146. //----------------------------------------------------------------------------------------
  147.  
  148. CRoundRectShape::CRoundRectShape(CDrawPart* drawPart):
  149.     CBoundedShape(drawPart, kRRectShape, kFrameOnly),
  150.     fOvalSize(FW_CPoint(FW_IntToFixed(32), FW_IntToFixed(32)))
  151. {
  152.     FW_END_CONSTRUCTOR
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. // CRoundRectShape::CRoundRectShape
  157. //----------------------------------------------------------------------------------------
  158.  
  159. CRoundRectShape::CRoundRectShape(CDrawPart* drawPart, FW_CReadableStream& archive) :
  160.     CBoundedShape(drawPart, archive)
  161. {    
  162.     archive >> fOvalSize;
  163.     FW_END_CONSTRUCTOR
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. // CRoundRectShape::~CRoundRectShape
  168. //----------------------------------------------------------------------------------------
  169.  
  170. CRoundRectShape::~CRoundRectShape()
  171. {
  172.     FW_START_DESTRUCTOR
  173. }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. // CRoundRectShape::OutlineShape
  177. //----------------------------------------------------------------------------------------
  178.  
  179. void CRoundRectShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, const FW_CRect& rect)
  180. {
  181.     FW_CRect bounds(rect);
  182.     AdjustRectForPenSize(bounds, style.GetPenSize());
  183.     FW_CRoundRectShape::RenderRoundRect(gc,
  184.                                       bounds,
  185.                                     fOvalSize,
  186.                                       FW_kFrame,
  187.                                       ink, style);
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. // CRoundRectShape::RenderShape
  192. //----------------------------------------------------------------------------------------
  193.  
  194. void CRoundRectShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
  195. {
  196. FW_UNUSED(ev);
  197. FW_UNUSED(facet);
  198.     FW_CRect rect = GetRectGeometry();
  199.     AdjustRectForPenSize(rect, GetPenSize());
  200.  
  201.     if (HasFillStyle())
  202.         FW_CRoundRectShape::RenderRoundRect(gc, rect, fOvalSize, FW_kFill, fFillInk, fFillStyle);
  203.     
  204.     if (HasFrameStyle())
  205.         FW_CRoundRectShape::RenderRoundRect(gc, rect, fOvalSize, FW_kFrame, fFrameInk, fFrameStyle);
  206. }
  207.  
  208. //----------------------------------------------------------------------------------------
  209. // CRoundRectShape::HitTest
  210. //----------------------------------------------------------------------------------------
  211.  
  212. FW_Boolean CRoundRectShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
  213. {    
  214.     FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  215.     ODFacet* facet = theMouseEvent.GetFacet(ev);
  216.     FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
  217.     frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
  218.  
  219.     FW_CRect bounds = GetRectGeometry();
  220.     AdjustRectForPenSize(bounds, GetPenSize());
  221.  
  222.     FW_CRoundRectShape RRectShape(bounds, fOvalSize, HasFillStyle() ? FW_kFill : FW_kFrame);
  223.     return RRectShape.HitTest(gc, mouse, FW_IntToFixed(2));
  224. }
  225.  
  226. //----------------------------------------------------------------------------------------
  227. // CRoundRectShape::CalcClipShape
  228. //----------------------------------------------------------------------------------------
  229.  
  230. ODShape* CRoundRectShape::CalcClipShape(Environment* ev)
  231. {
  232.     FW_CRect bounds = GetRectGeometry();
  233.     AdjustRectForPenSize(bounds, GetPenSize());
  234.     
  235.     FW_CAcquiredODShape clipShape = ::FW_CreateRoundRectODShape(ev, bounds, fOvalSize);
  236.     
  237.     if (FrameOnly())
  238.     {
  239.         bounds.Inset(GetPenSize(), GetPenSize());
  240.         FW_CAcquiredODShape roundRectShape = ::FW_CreateRoundRectODShape(ev, bounds, fOvalSize);
  241.         clipShape->Subtract(ev, roundRectShape);
  242.     }
  243.     
  244.     return clipShape.Orphan();
  245. }
  246.  
  247. //----------------------------------------------------------------------------------------
  248. // CRoundRectShape::CreateShapeOutline
  249. //----------------------------------------------------------------------------------------
  250.  
  251. ODShape* CRoundRectShape::CreateShapeOutline(Environment *ev)
  252. {
  253.     FW_CRect bounds = GetRectGeometry();
  254.     AdjustRectForPenSize(bounds, GetPenSize());
  255.     
  256.     ODShape* dragRgn = ::FW_CreateRoundRectODShape(ev, bounds, fOvalSize);        // We don't acquire it because we return it
  257.     
  258.     ::FW_OutlineODShape(ev, dragRgn, GetPenSize());
  259.     
  260.     return dragRgn;
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. // CRoundRectShape::Read
  265. //----------------------------------------------------------------------------------------
  266.  
  267. void* CRoundRectShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  268. {
  269. FW_UNUSED(type);
  270.     // [HLX] This is a hack until I can register object with the archiver
  271.     CDrawReadableStream *drawArchive = (CDrawReadableStream*)&stream;
  272.     return FW_NEW(CRoundRectShape, (drawArchive->GetDrawPart(), stream));
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. // CRoundRectShape::Flatten
  277. //----------------------------------------------------------------------------------------
  278.  
  279. void CRoundRectShape::Flatten(FW_CWritableStream& archive)
  280. {    
  281.     CBoundedShape::Flatten(archive);
  282.     archive << fOvalSize;
  283. }
  284.  
  285. //----------------------------------------------------------------------------------------
  286. // CRoundRectShape::GetObjectClass
  287. //----------------------------------------------------------------------------------------
  288.  
  289. ODDescType CRoundRectShape::GetObjectClass() const
  290. {
  291.     return cRoundedRectangle;
  292. }
  293.